package com.bojiu.lawsearch.lawsearch.service.impl;

import com.bojiu.lawsearch.lawsearch.mapper.LogMapper;
import com.bojiu.lawsearch.lawsearch.model.Log;
import com.bojiu.lawsearch.lawsearch.model.Page;
import com.bojiu.lawsearch.lawsearch.service.LogService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;

/**
 * @author: afdiao
 * @Date：2020/4/5 15:29
 * @Description:
 */
@Slf4j
@Service
public class LogServiceImpl implements LogService {

    @Autowired
    LogMapper logMapper;

    @Override
    public Page<Log> queryPage(int pageNum, int pageSize, Log log) {
        PageHelper.startPage(pageNum, pageSize, true);
        List<Log> list = logMapper.queryPage(Optional.ofNullable(log).orElse(new Log()));
        PageInfo pageInfo = new PageInfo(list);
        Page page = new Page(pageInfo.getPageNum(), pageInfo.getPageSize(), pageInfo.getPages(), pageInfo.getTotal(), list);
        return page;
    }
}
